package cn.edu.neusoft.service.car;

import cn.edu.neusoft.config.OauthConfigUtil;
import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
import com.dahuatech.icc.oauth.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CarInfoHandler {
    @Autowired
    private OauthConfigUtil oauthConfigUtil;
    public GetAllCarInfoResponse getCarInfoByPage(GetAllCarInfoRequest getRecordPageRequest) {
        OauthConfigUserPwdInfo config = oauthConfigUtil.getOauthConfig();
        GetAllCarInfoResponse response=null;
        try {
            log.info("CarInfoHandler,getCarInfoByPage,request:{}", JSONUtil.toJsonStr(getRecordPageRequest));
            response = HttpUtils.executeJson("/evo-apigw/evo-brm/1.2.1/car/list-page", getRecordPageRequest,null, Method.POST , config, GetAllCarInfoResponse.class);
//            log.info("CarInfoHandler,getCarInfoByPage,response:{}", JSONUtil.toJsonStr(response));
        } catch (ClientException e) {
            log.error(e.getErrMsg(), e);
        }
        if(!response.isSuccess()) {
            log.info("获取车辆信息失败:{}",response.getErrMsg());
        }
        return response;
    }
}
